ioemu: Close file descriptors when forking processes.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Tue, 6 Mar 2007 16:51:42 +0000 (16:51 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Tue, 6 Mar 2007 16:51:42 +0000 (16:51 +0000)
Just leave stdin/stdout/stderr (and possibly tap fd) open.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
tools/ioemu/vl.c
tools/ioemu/vnc.c

index 283e86a4876eb9a8617cc443d88d8fb89cf93db0..0b78fa8650d9f6731fa5149a378679b7cca901bb 100644 (file)
@@ -3250,6 +3250,14 @@ static int net_tap_init(VLANState *vlan, const char *ifname1,
         pid = fork();
         if (pid >= 0) {
             if (pid == 0) {
+                int open_max = sysconf(_SC_OPEN_MAX), i;
+                for (i = 0; i < open_max; i++)
+                    if (i != STDIN_FILENO &&
+                        i != STDOUT_FILENO &&
+                        i != STDERR_FILENO &&
+                        i != fd)
+                        close(i);
+
                 parg = args;
                 *parg++ = (char *)setup_script;
                 *parg++ = ifname;
index 46f3614c21280ac1c06b1134d64ef74c4f2f89e4..d06b47a220fce74097ef4cc5e6485945d704fdc3 100644 (file)
@@ -1445,7 +1445,7 @@ int vnc_display_init(DisplayState *ds, int display, int find_unused, struct sock
 
 int vnc_start_viewer(int port)
 {
-    int pid;
+    int pid, i, open_max;
     char s[16];
 
     sprintf(s, ":%d", port);
@@ -1456,6 +1456,12 @@ int vnc_start_viewer(int port)
        exit(1);
 
     case 0:    /* child */
+       open_max = sysconf(_SC_OPEN_MAX);
+       for (i = 0; i < open_max; i++)
+           if (i != STDIN_FILENO &&
+               i != STDOUT_FILENO &&
+               i != STDERR_FILENO)
+               close(i);
        execlp("vncviewer", "vncviewer", s, NULL);
        fprintf(stderr, "vncviewer execlp failed\n");
        exit(1);